﻿<navigation:Page x:Class="RialternativeSample.Views.CustomersView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                 xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
                 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                 xmlns:s="clr-namespace:FirstLook.ServiceModel.DomainServices.Client.Security;assembly=FirstLook.ServiceModel.DomainServices.Client.Security"
                 mc:Ignorable="d"
                 d:DesignWidth="640"
                 d:DesignHeight="480"
                 Title="Customers"
                 s:Authorization.RequiresAuthentication="True"
                 Style="{StaticResource PageStyle}"
                 DataContext="{Binding CustomersViewModel, Source={StaticResource ViewModelLocator}}">
    <navigation:Page.Resources>
        <CollectionViewSource Source="{Binding Customers}"
                              x:Name="customersCollection" />
    </navigation:Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="2*" />
        </Grid.RowDefinitions>
        <sdk:DataGrid x:Name="customersDataGrid"
                      IsReadOnly="True"
                      AutoGenerateColumns="False"
                      ItemsSource="{Binding Source={StaticResource customersCollection}}"
                      Margin="0,0,0,15">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Header="Id"
                                        Binding="{Binding CustomerID}" />
                <sdk:DataGridTextColumn Header="Company name"
                                        Binding="{Binding CompanyName}" />
                <sdk:DataGridTextColumn Header="Contact name"
                                        Binding="{Binding ContactName}" />
                <sdk:DataGridTextColumn Header="Contact title"
                                        Binding="{Binding ContactTitle}" />
                <sdk:DataGridTextColumn Header="Phone"
                                        Binding="{Binding Phone}" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
        <sdk:GridSplitter VerticalAlignment="Bottom"
                          HorizontalAlignment="Stretch" />
        <Grid Grid.Row="1"
              Margin="0,10,0,0">
            <Button Command="{Binding DeleteCustomerCommand}"
                    VerticalAlignment="Top"
                    HorizontalAlignment="Right"
                    Content="Delete"
                    Margin="0,0,3,0"
                    CommandParameter="{Binding SelectedItem, ElementName=customersDataGrid}"
                    Height="25" />
            <sdk:TabControl>
                <sdk:TabItem Header="Details">
                    <toolkit:DataForm x:Name="CustomerDetails"
                                      AutoCommit="False"
                                      AutoEdit="false"
                                      IsReadOnly="{Binding CanEditCustomers, Converter={StaticResource NotOperatorValueConverter}}"
                                      HeaderTemplate="{x:Null}"
                                      CommandButtonsVisibility="Commit,Cancel,Edit"                                      
                                      ItemsSource="{Binding Source={StaticResource customersCollection}}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="EditEnded">
                                <i:InvokeCommandAction Command="{Binding EndCustomerEditCommand}"
                                                       CommandParameter="{Binding CurrentItem, ElementName=CustomerDetails}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </toolkit:DataForm>
                </sdk:TabItem>
                <sdk:TabItem Header="Orders">
                    <!--s:Authorization.RequiresRole="CustomerManager"-->
                    <sdk:DataGrid ItemsSource="{Binding CurrentItem.Orders, Source={StaticResource customersCollection}}"
                                  IsReadOnly="True"
                                  AutoGenerateColumns="False">
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTextColumn Header="Order date"
                                                    Binding="{Binding OrderDate}" />
                            <sdk:DataGridTextColumn Header="Required date"
                                                    Binding="{Binding RequiredDate}" />
                            <sdk:DataGridTextColumn Header="Shipped date"
                                                    Binding="{Binding ShippedDate}" />
                            <sdk:DataGridTextColumn Header="Ship via"
                                                    Binding="{Binding ShipVia}" />
                            <sdk:DataGridTextColumn Header="Freight"
                                                    Binding="{Binding Freight}" />
                            <sdk:DataGridTextColumn Header="Ship name"
                                                    Binding="{Binding ShipName}" />
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>
                </sdk:TabItem>
            </sdk:TabControl>
        </Grid>
    </Grid>
</navigation:Page>
